package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {
    @Select("select count(id) from setmeal where category_id=#{id};")
    Integer countByCategoryId(Long id);

    @AutoFill(OperationType.INSERT)
    void save(Setmeal setmeal);

    //    分页查询套餐
    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

//    根据id查询套餐
    @Select("select * from setmeal where id=#{id}")
    Setmeal getById(Long id);

    //    删除套餐
    @Delete("delete from setmeal where id=#{setmealId}")
    void deleteById(Long setmealId);

//    修改套餐表
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

//    根据条件查询套餐
    List<Setmeal> list(Setmeal setmeal);

//    根据套餐id查询包含的菜品
    @Select("SELECT sd.name, sd.copies, d.image, d.description FROM setmeal_dish sd LEFT JOIN dish d ON sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long id);

    Integer countByMap(Map map);
}
